using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for CarDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarMoreDetailDB
    {
        public CarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarMoreDetail carmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("CECarMoreDetailId", carmoredetail.CECarMoreDetailId);
            _sPara.Add("CECarID", carmoredetail.CECarId);
            _sPara.Add("TransmissionType", carmoredetail.TransmissionType);
            _sPara.Add("TypeOfPropellent", carmoredetail.TypeOfPropellent);
            _sPara.Add("EngineNo", carmoredetail.EngineNo);
            _sPara.Add("ChassicNo", carmoredetail.ChassicNo);
            _sPara.Add("HirePurchaseCompany", carmoredetail.HirePurchaseCompany);
            _sPara.Add("HasAccessary", carmoredetail.HasAccessary);
            _sPara.Add("HasPreInsurer", carmoredetail.HasPreInsurer);
            _sPara.Add("HasRevokeLicense", carmoredetail.HasRevokeLicense);
            _sPara.Add("NCDReason", carmoredetail.NCDReason);
            _sPara.Add("NCDOtherReason", carmoredetail.NCDOtherReason);
            _sPara.Add("@RefCEUserId", carmoredetail.RefCEUserId);
            _sPara.Add("@CurrentStep", carmoredetail.CurrentStep);
            _sPara.Add("@ViewedDetailId", carmoredetail.ViewedDetailId);
            _sPara.Add("@Status", carmoredetail.Status);
            _sPara.Add("@Info1", carmoredetail.Info1);
            _sPara.Add("@Info2", carmoredetail.Info2);
            _sPara.Add("@Info3", carmoredetail.Info3);
            _sPara.Add("@Info4", carmoredetail.Info4);
            _sPara.Add("@Info5", carmoredetail.Info5);
            _sPara.Add("@Info6", carmoredetail.Info6);
            _sPara.Add("@Info7", carmoredetail.Info7);
            _sPara.Add("@Info8", carmoredetail.Info8);
            _sPara.Add("@Info9", carmoredetail.Info9);
            _sPara.Add("@Info10", carmoredetail.Info10);
            _sPara.Add("@Info11", carmoredetail.Info11);
            _sPara.Add("@Info12", carmoredetail.Info12);
            _sPara.Add("@Info13", carmoredetail.Info13);
            _sPara.Add("@Info14", carmoredetail.Info14);
            _sPara.Add("@Info15", carmoredetail.Info15);
            _sPara.Add("@Info16", carmoredetail.Info16);
            _sPara.Add("@Info17", carmoredetail.Info17);
            _sPara.Add("@Info18", carmoredetail.Info18);
            _sPara.Add("@Info19", carmoredetail.Info19);
            _sPara.Add("@Info20", carmoredetail.Info20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public CarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            CarMoreDetail _cardetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                _cardetail = new CarMoreDetail();
                _cardetail = FillDataRecord(_dt);
            }
            return _cardetail;
        }

        #region Comment
        //public CarDetail GetCar(string GUID)
        //{
        //    CarDetail _cardetail = null;
        //    MyDatabase _db = new MyDatabase();
        //    string _spName = "sprocCarDetailByGUIDSelectSingleItem";

        //    SortedList _spara = new SortedList();
        //    _spara.Add("@GUID", GUID);

        //    using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
        //    {
        //        if (_dt != null && _dt.Rows.Count > 0)
        //        {
        //            _cardetail = new CarDetail();
        //            _cardetail = FillDataRecord(_dt);
        //        }
        //    }
        //    return _cardetail;
        //}

        //public string GetGUID(Int64 CarId)
        //{
        //    MyDatabase _db = new MyDatabase();
        //    string strSQL = "Select ROWGUID from tblCarDetail Where [CECarId] = @CECarID";

        //    SortedList _spara = new SortedList();
        //    _spara.Add("@CECarID", CarId);

        //    object _result = _db.ExecuteScalarSqlStatement(strSQL, _spara);

        //    return _result.ToString();
        //}
        #endregion

        private CarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            CarMoreDetail myCar = new CarMoreDetail();
            myCar.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCar.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarID"].ToString());
            myCar.TransmissionType = myDataTable.Rows[0]["TransmissionType"].ToString();
            myCar.TypeOfPropellent = myDataTable.Rows[0]["TypeOfPropellent"].ToString();
            myCar.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCar.ChassicNo = myDataTable.Rows[0]["ChassicNo"].ToString();
            myCar.HirePurchaseCompany = myDataTable.Rows[0]["HirePurchaseCompany"].ToString();
            myCar.HasAccessary = Convert.ToBoolean(myDataTable.Rows[0]["HasAccessary"].ToString());
            myCar.HasPreInsurer = Convert.ToBoolean(myDataTable.Rows[0]["HasPreInsurer"].ToString());
            myCar.NCDReason = myDataTable.Rows[0]["NCDReason"].ToString();
            myCar.NCDOtherReason = myDataTable.Rows[0]["NCDOtherReason"].ToString();
            myCar.HasRevokeLicense = Convert.ToBoolean(myDataTable.Rows[0]["HasRevokeLicense"].ToString());
            myCar.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCar.Status = myDataTable.Rows[0]["Status"].ToString();

            myCar.Info1 = myDataTable.Rows[0]["Info1"].ToString();
            myCar.Info2 = myDataTable.Rows[0]["Info2"].ToString();
            return myCar;
        }
    }
}